if (redis.call('hexists', KEYS[1], KEYS[2]) == 1) then
    local stock = tonumber(redis.call('hget', KEYS[1], KEYS[2]));
    if (stock > 0) then
        redis.call('decrby', KEYS[1], KEYS[2], 1);
        return stock;
    elseif (stock == 0) then
        return 0;
    end;
end;
return nil;